package com.test.deencredit.dialog_deencredit;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.deencredit.R;
import com.test.deencredit.bean_deencredit.config_deencredit.AppShowCustomize_deencredit;
import com.test.deencredit.bean_deencredit.userinfo_deencredit.OthersInfo_deencredit;


public class BindAccountChannelDialog_Fr_deencredit extends Dialog {

    private final String mobile_deencredit;

    private final Runnable denyRunnable_deencredit, addAccountRunnable_deencredit;

    private ImageView logoIv_deencredit;
    private TextView channelTv_deencredit, mobileTv_deencredit;
    private Button denyBtn_deencredit, addBtn_deencredit;

    public BindAccountChannelDialog_Fr_deencredit(@NonNull Context context, String mobile, Runnable denyRunnable, Runnable addAccountRunnable) {
        super(context);
        this.mobile_deencredit = mobile;
        this.denyRunnable_deencredit = denyRunnable;
        this.addAccountRunnable_deencredit = addAccountRunnable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_bind_account_channel_fr_deencredit);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        logoIv_deencredit = findViewById(R.id.dbacf_iv_logo);
        channelTv_deencredit = findViewById(R.id.dbacf_tv_channel);
        mobileTv_deencredit = findViewById(R.id.dbacf_tv_mobile);
        denyBtn_deencredit = findViewById(R.id.dbacf_btn_deny);
        addBtn_deencredit = findViewById(R.id.dbacf_btn_add);

        TextView textTv = findViewById(R.id.dbacf_tv_text);
        textTv.setText(getContext().getString(R.string.bindaccountchannel_fr_text_1_deencredit).replaceAll("xxx", OthersInfo_deencredit.getInstance_deencredit().getChannel_deencredit()));

        initView_deencredit();
    }

    @SuppressLint("SetTextI18n")
    private void initView_deencredit(){

        String channel = OthersInfo_deencredit.getInstance_deencredit().getChannel_deencredit();

        //获取图标
        Bitmap logoBm = AppShowCustomize_deencredit.getInstance_deencredit().getChannelLogoByValue_deencredit(channel);
        if (logoBm!=null) logoIv_deencredit.setImageBitmap(logoBm);

        mobileTv_deencredit.setText(mobile_deencredit);
        channelTv_deencredit.setText(channel);

        denyBtn_deencredit.setOnClickListener(v -> {
            if (denyRunnable_deencredit !=null) denyRunnable_deencredit.run();
            dismiss();
        });

        addBtn_deencredit.setOnClickListener(v -> {
            if (addAccountRunnable_deencredit !=null) addAccountRunnable_deencredit.run();
            dismiss();
        });

    }

}
